﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <WtmSearcher v-model="searchDataMeterDataRecord" @search="()=>{getTableDataMeterDataRecord();}">
      <el-row>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="DeviceId_FormItem" prop="DeviceId" :label="$t('message.autotrans._Model_MeterDataRecord_Device')">
            <el-select v-model="searchDataMeterDataRecord.DeviceId" clearable>
               <el-option v-for="item in stateMeterDataRecord.AllDevices" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="Source_FormItem" prop="Source" :label="$t('message.autotrans._Model_MeterDataRecord_Source')">
            <el-select v-model="searchDataMeterDataRecord.Source" clearable>
               <el-option key="AutoCollect" value="AutoCollect" :label="$t('message.autotrans._Enum_DataSourceEnum_AutoCollect')"></el-option>
               <el-option key="ManualInput" value="ManualInput" :label="$t('message.autotrans._Enum_DataSourceEnum_ManualInput')"></el-option>
               <el-option key="Import" value="Import" :label="$t('message.autotrans._Enum_DataSourceEnum_Import')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CollectStatus_FormItem" prop="CollectStatus" :label="$t('message.autotrans._Model_MeterDataRecord_CollectStatus')">
            <el-select v-model="searchDataMeterDataRecord.CollectStatus" clearable>
               <el-option key="Success" value="Success" :label="$t('message.autotrans._Enum_CollectStatusEnum_Success')"></el-option>
               <el-option key="Failed" value="Failed" :label="$t('message.autotrans._Enum_CollectStatusEnum_Failed')"></el-option>
               <el-option key="Timeout" value="Timeout" :label="$t('message.autotrans._Enum_CollectStatusEnum_Timeout')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="IsAbnormal_FormItem" prop="IsAbnormal" :label="$t('message.autotrans._Model_MeterDataRecord_IsAbnormal')">
            <el-select v-model="searchDataMeterDataRecord.IsAbnormal" clearable>
               <el-option :key="1" :value=true :label="$t('message._system.common.vm.tips_bool_true')"></el-option>
               <el-option :key="0" :value=false :label="$t('message._system.common.vm.tips_bool_false')"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="AbnormalReason_FormItem" prop="AbnormalReason" :label="$t('message.autotrans._Model_MeterDataRecord_AbnormalReason')">
            <el-input v-model="searchDataMeterDataRecord.AbnormalReason" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="CurrentValue_FormItem" prop="CurrentValue" :label="$t('message.autotrans._Model_MeterDataRecord_CurrentValue')">
            <el-input v-model="searchDataMeterDataRecord.CurrentValue" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="ParameterId_FormItem" prop="ParameterId" :label="$t('message.autotrans._Model_MeterDataRecord_Parameter')">
            <el-select v-model="searchDataMeterDataRecord.ParameterId" clearable>
               <el-option v-for="item in stateMeterDataRecord.AllParameters" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="ParameterName_FormItem" prop="ParameterName" :label="$t('message.autotrans._Model_MeterDataRecord_ParameterName')">
            <el-input v-model="searchDataMeterDataRecord.ParameterName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="DataValueType_FormItem" prop="DataValueType" :label="$t('message.autotrans._Model_MeterDataRecord_DataValueType')">
            <el-select v-model="searchDataMeterDataRecord.DataValueType" clearable>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="Usage_FormItem" prop="Usage" :label="$t('message.autotrans._Model_MeterDataRecord_Usage')">
            <el-input v-model="searchDataMeterDataRecord.Usage" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="Unit_FormItem" prop="Unit" :label="$t('message.autotrans._Model_MeterDataRecord_Unit')">
            <el-input v-model="searchDataMeterDataRecord.Unit" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="8" class="mb20">
        <el-form-item ref="ReadingTime_FormItem" prop="ReadingTime" :label="$t('message.autotrans._Model_MeterDataRecord_ReadingTime')">
            <el-date-picker v-model="searchDataMeterDataRecord.ReadingTime" type='daterange' clearable></el-date-picker>
        </el-form-item>

        </el-col>
      </el-row>

  </WtmSearcher>

  <div style="text-align: right;">
      <WtmButton v-auth="'/api/IoTManagement/MeterDataRecord/Create'" icon='fa fa-plus' type='primary' :button-text="$t('message.autotrans.SysCreate')" @click="OnCreateClick()"/>
    <WtmButton v-auth="'/api/IoTManagement/MeterDataRecord/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" @click="onBatchDelete()"/>
    <WtmButton v-auth="'/api/IoTManagement/MeterDataRecord/BatchEdit'" icon='fa fa-pencil-square' type='primary' :button-text="$t('message.autotrans.SysBatchEdit')" @click="OnBatchEditClick()"/>
    <WtmButton v-auth="'/api/IoTManagement/MeterDataRecord/Import'" icon='fa fa-tasks' type='primary' :button-text="$t('message.autotrans.SysImport')" @click="OnImportClick()"/>
    <WtmButton v-auth="'/api/IoTManagement/MeterDataRecord/MeterDataRecordExportExcel'"  icon='fa fa-arrow-circle-down' type='primary' :button-text="$t('message.autotrans.SysExport')" @click="onExport()"/>

  </div>
  <WtmTable ref="tableRefMeterDataRecord" v-bind="tableDataMeterDataRecord">
    <template #operation>
      <el-table-column :label="$t('message._system.common.vm.operate')" width="180">
        <template v-slot="scope">
            <WtmButton v-auth="'/api/IoTManagement/MeterDataRecord/Edit'" :is-text="true" icon='fa fa-pencil-square' type='warning' :button-text="$t('message.autotrans.SysEdit')" @click="OnEditrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/IoTManagement/MeterDataRecord/{id}'" :is-text="true" icon='fa fa-info-circle' type='info' :button-text="$t('message.autotrans.Page详情')" @click="OnDetailsrowClick(scope.row)"/>
          <WtmButton v-auth="'/api/IoTManagement/MeterDataRecord/BatchDelete'"  icon='fa fa-trash' type='danger' :button-text="$t('message.autotrans.SysDelete')" :confirm="$t('message._system.common.vm.deletetip')" :is-text="true"  @click="onDelete(scope.row)"/>

        </template>
      </el-table-column>
    </template>
  </WtmTable>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageIoTManagementMeterDataRecordIndex;true;Digitalmes.IoTManagement.Controllers;MeterDataRecord">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { meterdatarecordApi } from '/@/api/iotmanagement/meterdatarecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;

const CreateDialog = defineAsyncComponent(() => import('./create.vue'));
const EditDialog = defineAsyncComponent(() => import('./edit.vue'));
const DetailsDialog = defineAsyncComponent(() => import('./details.vue'));
const BatchEditDialog = defineAsyncComponent(() => import('./batchedit.vue'));
const ImportDialog = defineAsyncComponent(() => import('./import.vue'));

const stateMeterDataRecord = reactive({
    
    AllDevices: [] as any[],
    AllParameters: [] as any[],
});

const searchDataMeterDataRecord = ref({
        DeviceId: null,
        Source: undefined,
        CollectStatus: undefined,
        IsAbnormal: undefined,
        AbnormalReason: '',
        CurrentValue: null,
        ParameterId: null,
        ParameterName: '',
        DataValueType: undefined,
        Usage: null,
        Unit: '',
        ReadingTime: undefined,
});

// 定义变量内容
const tableRefMeterDataRecord = ref();
const tableDataMeterDataRecord = ref({
    // 列表数据（必传）
    data: [],
	// 表头内容（必传，注意格式）
	header: [
      {title:ci.proxy.$t('message.autotrans.Page设备'),key: 'MeterDataRecord_Device',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page数据来源'),key: 'MeterDataRecord_Source',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page采集状态'),key: 'MeterDataRecord_CollectStatus',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page异常标记'),key: 'MeterDataRecord_IsAbnormal',type: 'switch',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page异常原因'),key: 'MeterDataRecord_AbnormalReason',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page当前读数'),key: 'MeterDataRecord_CurrentValue',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page数据'),key: 'MeterDataRecord_Parameter',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page数据名称'),key: 'MeterDataRecord_ParameterName',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page数据类型'),key: 'MeterDataRecord_DataValueType',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page本次用量'),key: 'MeterDataRecord_Usage',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page单位'),key: 'MeterDataRecord_Unit',type: 'text',isCheck: true},
      {title:ci.proxy.$t('message.autotrans.Page读数时间'),key: 'MeterDataRecord_ReadingTime',type: 'text',isCheck: true},

	],
	// 配置项（必传）
	config: {
        total: 0, // 列表总数
		loading: true, // loading 加载
		isSerialNo: true, // 是否显示表格序号
		isSelection: true, // 是否显示表格多选
		isOperate: true, // 是否显示表格操作栏
	}
});
// 初始化表格数据
const getTableDataMeterDataRecord = () => {
    tableRefMeterDataRecord.value.doSearch(meterdatarecordApi().search, searchDataMeterDataRecord.value)
        .catch((error: any) => {
			other.setFormError(ci, error);
		});
};
const OnCreateClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysCreate'), CreateDialog, null, getTableDataMeterDataRecord)
};

const OnEditrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysEdit'), EditDialog, row, getTableDataMeterDataRecord)
};

const OnDetailsrowClick = (row: any) => {
    other.openDialog(ci.proxy.$t('message.autotrans.Page详情'), DetailsDialog, row, getTableDataMeterDataRecord)
};

// 删除
const onDelete = (row: any) => {
    meterdatarecordApi().delete([row.ID]).then(() => { getTableDataMeterDataRecord()})
};

const onBatchDelete = () => {
    const selectedrows = tableRefMeterDataRecord.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      meterdatarecordApi().delete(selectedids).then(() => { getTableDataMeterDataRecord()})
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnBatchEditClick = () => {
    const selectedrows = tableRefMeterDataRecord.value.getSelectedRows();
    const selectedids = selectedrows.map((x: any) => x.ID);
    if (selectedids.length > 0)
      other.openDialog(ci.proxy.$t('message.autotrans.SysBatchEdit'), BatchEditDialog, selectedids, getTableDataMeterDataRecord)
    else
      ElMessage.error(ci.proxy.$t('message._system.common.vm.check'));
};

const OnImportClick = () => {
    other.openDialog(ci.proxy.$t('message.autotrans.SysImport'), ImportDialog, null, getTableDataMeterDataRecord)
};

const onExport = () => {
	const selected = tableRefMeterDataRecord.value.getSelectedRows();
	if (selected.length > 0) {
		meterdatarecordApi().exportById(selected.map((x: any) => x.ID));
	}
	else {
		meterdatarecordApi().export({});
	}
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/IoTManagement/MeterDataRecord/GetMeterDevices',[],false).then(x=>{stateMeterDataRecord.AllDevices = x});
    other.getSelectList('/api/IoTManagement/MeterDataRecord/GetMeterParameters',[],false).then(x=>{stateMeterDataRecord.AllParameters = x});
        getTableDataMeterDataRecord();

});

// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

